<?php
class brand_model extends CI_Model
{
    protected $_table = "mock_brand";
    protected $_tableproduct = "mock_products";
    public function __construct(){
        parent::__construct();
    }
    public function listBrand($end,$start)
    {
        $this->db->limit($end,$start);
        return $this->db->get($this->_table)->result_array();
    }
    public function listBran_product(){
        return $this->db->get($this->_table)->result_array();
    }
    public function totalBrand()
    {
        return $this->db->count_all($this->_table);
    }
    public function GetData($id)
    {
        $this->db->where("brand_id",$id);
        return $this->db->get($this->_table)->row_array();
    }
    function get_item_list()
    {
        $this->db->orderby('brand_name','ASC');
        return $this->db->get($this->_table)->result_array();
    }
    public function delBrand($id){
        $this->db->where("brand_id",$id);
        $this->db->delete($this->_table);
    }
    public function delProduct($id){
        $brand = "";
        $dbarray = array(
            'brand_id' => $brand
        );
        $this->db->where("brand_id",$id);
        $this->db->update($this->_tableproduct,$dbarray);
    }
    public function checkName($name){
        $this->db->where("brand_name",$name);
        $numName = $this->db->count_all_results($this->_table);
        if($numName >0){
            return FALSE;
        }else{
            return TRUE;
        }
    }
    public function addBrand($data){
        return $this->db->insert($this->_table,$data);
    }
}